<?php

/**
 * 报单币日志管理
 * * @网店运维 (c) 2015-2018 ShopWWI Inc. (http://www.shopwwi.com)
 * @license    http://www.shopwwi.c om
 * @link       交流群号：111731672
 * @since      网店运维提供技术支持 授权请购买shopnc授权
 */

defined('ByShopWWI') or exit('Access Invalid!');

class coinControl extends BaseMemberControl {

	public function __construct() {
            parent::__construct();
            Language::read('member_predeposit');

	}

        /**
	 * 充值列表
	 */
	public function indexOp() {

            $condition = array();
            $condition['pdr_member_id'] = $_SESSION['member_id'];
            if (!empty($_GET['pdr_sn'])) {
               $condition['pdr_sn'] = $_GET['pdr_sn'];
            }

            $model_coin= Model('coin');
            $list = $model_coin -> getCoinRechargeList($condition, 20, '*', 'pdr_id desc');
            self::profile_menu('log', 'recharge_list');
            Tpl::output('list', $list);
            Tpl::output('show_page', $model_coin -> showpage());
            Tpl::showpage('coin.coin_list');

	}
        
	/**
	 * 充值添加
	 */
	 public function recharge_addOp(){
            if (!chksubmit()){
                //信息输出
                self::profile_menu('recharge_add','recharge_add');
                Tpl::showpage('coin.recharge_add');
                exit();
            }
            $pdr_amount = abs(floatval($_POST['pdr_amount']));
            if ($pdr_amount <= 0) {
                showMessage(Language::get('predeposit_recharge_add_pricemin_error'),'','html','error');
            }
            $model_coin = Model('coin');
            $data = array();
            $data['pdr_sn'] = $pay_sn = $model_coin->makeSn();
            $data['pdr_member_id'] = $_SESSION['member_id'];
            $data['pdr_member_name'] = $_SESSION['member_name'];
            $data['pdr_amount'] = $pdr_amount;
            $data['pdr_add_time'] = TIMESTAMP;
            $insert = $model_coin->addCoinRecharge($data);
            if ($insert) {
                //转向到商城支付页面
                redirect(SHOP_SITE_URL . '/index.php?act=buy&op=coin_pay&pay_sn='.$pay_sn);
            }
        }

	

	

	/**
	 * 查看充值详细
	 *
	 */
	public function recharge_showOp() {
		$pdr_id = intval($_GET["id"]);
		if ($pdr_id <= 0) {
			showDialog(Language::get('predeposit_parameter_error'), '', 'error');
		}

		$model_coin = Model('coin');
		$condition = array();
		$condition['pdr_member_id'] = $_SESSION['member_id'];
		$condition['pdr_id'] = $pdr_id;
		$condition['pdr_payment_state'] = 1;
		$info = $model_coin->getCoinRechargeInfo($condition);
		if (!$info) {
			showDialog(Language::get('predeposit_record_error'), '', 'error');
		}

		Tpl::output('info', $info);
		self::profile_menu('rechargeinfo', 'rechargeinfo');
		Tpl::showpage('coin.coin_info');

	}

	/**
	 * 删除充值记录
	 *
	 */
	public function recharge_delOp() {

		$pdr_id = intval($_GET["id"]);
		if ($pdr_id <= 0) {
			showDialog(Language::get('predeposit_parameter_error'), '', 'error');
		}

		$model_coin = Model('coin');
		$condition = array();
		$condition['pdr_member_id'] = $_SESSION['member_id'];
		$condition['pdr_id'] = $pdr_id;
		$condition['pdr_payment_state'] = 0;
		$result = $model_coin -> delCoinRecharge($condition);

		if ($result) {
			showDialog(Language::get('nc_common_del_succ'), 'reload', 'succ', 'CUR_DIALOG.close()');
		} else {
			showDialog(Language::get('nc_common_del_fail'), '', 'error');
		}

	}

	/**
	 * 报单币变更日志
	 */
	public function coin_log_listOp() {

            $model_coin = Model('coin');
            $condition = array();
            $condition['lg_member_id'] = $_SESSION['member_id'];
            $list = $model_coin->getCoinRecordList($condition, 20, '*', 'lg_id desc');

            //信息输出
            self::profile_menu('log', 'loglist');
            Tpl::output('show_page', $model_coin -> showpage());
            Tpl::output('list', $list);
            Tpl::showpage('coin.coin_log_list');

	}

	




	/**
	 * 用户中心右边，小导航
	 *
	 * @param string    $menu_type  导航类型
	 * @param string    $menu_key   当前导航的menu_key
	 * @return
	 */
	private function profile_menu($menu_type, $menu_key = '') {

		$menu_array = array( 
                    array('menu_key' => 'loglist', 'menu_name' => '报单币余额', 'menu_url' => 'index.php?act=coin&op=coin_log_list'), 
                    array('menu_key' => 'recharge_list', 'menu_name' => '充值明细', 'menu_url' => 'index.php?act=coin&op=index'), 
                );

		switch ($menu_type) {
			case 'rechargeinfo' :
				$menu_array[] = array('menu_key' => 'rechargeinfo', 'menu_name' => '充值详细', 'menu_url' => '');
				break;
			case 'recharge_add' :
				$menu_array[] = array('menu_key' => 'recharge_add', 'menu_name' => '在线充值', 'menu_url' => '');
				break;
			case 'log' :
			default :
				break;
		}

		Tpl::output('member_menu', $menu_array);
		Tpl::output('menu_key', $menu_key);

	}

}
